#pragma once

#include <string>
#include <unordered_map>
#include <memory>

class Item;
typedef std::shared_ptr<Item> ItemPtr;

class ItemManager;
typedef std::shared_ptr<ItemManager> ItemManagerPtr;

class ItemManager
{
public:
	static ItemManagerPtr getSingleton();
	ItemManager();
	~ItemManager();

	void init(const std::string &path);

    const ItemPtr &get(unsigned int item_id) const;

protected:
    struct TempItemData
	{
		std::string description;
        std::vector<unsigned int> settings; //Item::Settings is undefined in this scope, so we identify by unsigned int
	};
    typedef std::unique_ptr<TempItemData> TempItemDataPtr;

    void parseDescription(const std::vector<std::string> &lines, unsigned int &index, std::string &description);

    void parseSettings(const std::vector<std::string> &lines, unsigned int &index, std::vector<unsigned int> &settings);
	void applySettings(std::unordered_map<unsigned int, ItemPtr>::iterator &it);

	static ItemManagerPtr singleton;
	std::unordered_map<unsigned int, ItemPtr> items;
    std::unordered_map<unsigned int, TempItemDataPtr> temp_item_data;
	ItemPtr null_item;
};
